/* $Id: CategoryListView.java 85 2007-12-20 06:50:58Z osborn.steven $
 * 
 * Undroid Package Manager
 *
 * Copyright 2007 Steven Osborn
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 */
package com.bitsetters.undroid;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/**
 * 
 * @author Steven Osborn - http://steven.bitstters.com
 */
public class CategoryListView extends TableLayout {

    private ImageView mIcon;
    private TextView mText;
    private TextView mCount;

    /**
     * 
     * @param context
     * @param text
     * @param icon
     * @param count
     */
    public CategoryListView(Context context, String text, Drawable icon,
            int count) {

        super(context);

        // Create row container
        TableRow row = new TableRow(context);

        mIcon = new ImageView(context);
        mIcon.setImageDrawable(icon);

        mText = new TextView(context);
        mText.setText(text);

        mCount = new TextView(context);
        mCount.setText("(" + String.valueOf(count) + ")");

        // left, top, right, bottom
        mIcon.setPadding(5, 0, 10, 0);
        mCount.setPadding(0, 15, 10, 10);
        mText.setPadding(0, 15, 0, 10);


        row.setGravity(Gravity.CENTER_VERTICAL);

        // Add buttons to row
        row.addView(mIcon, new TableRow.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        row.addView(mText, new TableRow.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        row.addView(mCount, new TableRow.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        setColumnStretchable(1, true);
        addView(row,new TableLayout.LayoutParams());
    }

    /**
     * 
     * @param icon
     */
    public void setIcon(Drawable icon) {
        mIcon.setImageDrawable(icon);
    }

    /**
     * 
     * @param text
     */
    public void setText(String text) {
        mText.setText(text);
    }

    /**
     * 
     * @param count
     */
    public void setCount(int count) {
        mCount.setText(String.valueOf(count));
    }
    
    

}
